package com.compass.doctor.ui.chat.util

import com.compass.doctor.R
import com.compass.doctor.ui.chat.attachment.ArticleAttachment
import com.compass.doctor.ui.chat.attachment.ExamineAttachment
import com.compass.doctor.ui.chat.attachment.HospitalizationCertificateAttachment
import com.compass.doctor.ui.chat.attachment.InquiryAttachment
import com.compass.doctor.ui.chat.attachment.PostDiagnosisAttachment
import com.compass.doctor.ui.chat.attachment.PrescriptionAttachment
import com.compass.framework.model.Drug
import com.compass.framework.model.MessageBody
import com.compass.framework.model.PrescriptionInformation
import com.compass.framework.toast.TipsToast
import com.compass.framework.utils.getStringFromResource
import com.netease.nimlib.sdk.msg.MessageBuilder
import com.netease.nimlib.sdk.msg.constant.SessionTypeEnum
import com.netease.yunxin.kit.chatkit.repo.ChatRepo
import com.netease.yunxin.kit.corekit.im.provider.FetchCallback



    /**
     * 发送问诊单消息
     * @param patientName 患者姓名
     * @param age
     * @param describe
     * @param sex
     * @param patientId
     */
    fun sendInquiryMessage(patientName: String, age: String, describe: String, sex: String,patientId:String,sessionId:String) {
        //创建IMMessage，其中sessionId代表会话ID，sessionType会话类型，content代表消息内容，customerAttachment自定义消息
        var attachment = InquiryAttachment()
        attachment.setInquiryData( patientName, age, describe, sex,patientId )
        ChatRepo.sendMessage(
            MessageBuilder.createCustomMessage(
                sessionId,
                SessionTypeEnum.P2P,
                getStringFromResource(R.string.attachment_inquiry_msg),
                attachment
            ), false, object :
                FetchCallback<Void> {
                override fun onException(exception: Throwable?) {
                    TipsToast.showTips("onException${exception?.message}")
                }

                override fun onFailed(code: Int) {

                }

                override fun onSuccess(param: Void?) {
                    TipsToast.showTips("发送成功")
                }

            })
    }


    /**
     * 发送诊后建议
     * @param content 诊后建议内容
     * @param id
     */
    fun sendPostDiagnosisMessage(content: String,sessionId:String) {
        //创建IMMessage，其中sessionId代表会话ID，sessionType会话类型，content代表消息内容，customerAttachment自定义消息
        var attachment = PostDiagnosisAttachment()
        attachment.setPostData( content)
        ChatRepo.sendMessage(
            MessageBuilder.createCustomMessage(
                sessionId,
                SessionTypeEnum.P2P,
                getStringFromResource(R.string.attachment_post_msg),
                attachment
            ), false, object :
                FetchCallback<Void> {
                override fun onException(exception: Throwable?) {
                    TipsToast.showTips("onException${exception?.message}")
                }

                override fun onFailed(code: Int) {

                }

                override fun onSuccess(param: Void?) {
                    TipsToast.showTips("发送成功")
                }

            })
    }


    /**
     * 发送文章消息
     * @param title 文章标题
     * @param content 文章内容
     * @param img 文章插图
     * @param doctorName 医生姓名
     * @param avatar 医生头像
     * @param professional 医生职称
     * @param professional 医生职称
     */
    fun sendArticleMessage(title: String, content: String, img:String,doctorName: String,avatar:String, professional : String,sessionId:String) {
        //创建IMMessage，其中sessionId代表会话ID，sessionType会话类型，content代表消息内容，customerAttachment自定义消息
        var attachment = ArticleAttachment()
        attachment.setArticleData(
            title, content,img,doctorName,avatar,professional)
        ChatRepo.sendMessage(
            MessageBuilder.createCustomMessage(
                sessionId,
                SessionTypeEnum.P2P,
                getStringFromResource(R.string.attachment_article_msg),
                attachment
            ), false, object :
                FetchCallback<Void> {
                override fun onException(exception: Throwable?) {
                    TipsToast.showTips("onException${exception?.message}")
                }

                override fun onFailed(code: Int) {

                }

                override fun onSuccess(param: Void?) {
                    TipsToast.showTips("发送成功")
                }

            })
    }


    /**
     * 处方单消息
     * @param diagnose 诊断
     * @param expense 费用
     * @param id 处方单id
     * @param info 药品信息

     */
    fun sendPrescriptionMessage(diagnose: String, price: Long,drugs: String, sessionId:String,id:String) {
        //创建IMMessage，其中sessionId代表会话ID，sessionType会话类型，content代表消息内容，customerAttachment自定义消息
        var attachment = PrescriptionAttachment()
        attachment.setPrescriptionData(
            diagnose, price,drugs,id)
        ChatRepo.sendMessage(
            MessageBuilder.createCustomMessage(
                sessionId,
                SessionTypeEnum.P2P,
                getStringFromResource(R.string.attachment_prescription_msg),
                attachment
            ), false, object :
                FetchCallback<Void> {
                override fun onException(exception: Throwable?) {
                    TipsToast.showTips("onException${exception?.message}")
                }

                override fun onFailed(code: Int) {

                }

                override fun onSuccess(param: Void?) {
                    TipsToast.showTips("发送成功")
                }

            })
    }



    /**
     * 住院证消息
     * @param diagnosisName 诊断
     * @param inpatientWardName 病区
     * @param id 住院证id
     * @param sessionId 会话 ID
     */
    fun sendHospitalizationMessage(diagnosisName: String?, inpatientWardName: String?, id:String,sessionId:String) {
        //创建IMMessage，其中sessionId代表会话ID，sessionType会话类型，content代表消息内容，customerAttachment自定义消息
        var attachment = HospitalizationCertificateAttachment()
        attachment.setHospitalizationData(
            diagnosisName, inpatientWardName,id)
        ChatRepo.sendMessage(
            MessageBuilder.createCustomMessage(
                sessionId,
                SessionTypeEnum.P2P,
                getStringFromResource(R.string.attachment_hospitalization_msg),
                attachment
            ), false, object :
                FetchCallback<Void> {
                override fun onException(exception: Throwable?) {
                    TipsToast.showTips("onException${exception?.message}")
                }

                override fun onFailed(code: Int) {

                }

                override fun onSuccess(param: Void?) {
                    TipsToast.showTips("创建成功")
                }

            })
    }



    /**
     * 检验检查消息
     * @param diagnosisName 诊断
     * @param departmentName 科室
     * @param id 检验检查id
     * @param inspectionName 检查项目
     */
    fun sendExamineMessage(diagnosisName: String?, departmentName: String?, inspectionName: String?, id: String, price :Long, sessionId:String) {
        //创建IMMessage，其中sessionId代表会话ID，sessionType会话类型，content代表消息内容，customerAttachment自定义消息
        var attachment = ExamineAttachment()
        attachment.setExamineData(
            diagnosisName, departmentName,inspectionName,id,price)
        ChatRepo.sendMessage(
            MessageBuilder.createCustomMessage(
                sessionId,
                SessionTypeEnum.P2P,
                getStringFromResource(R.string.attachment_examine_msg),
                attachment
            ), false, object :
                FetchCallback<Void> {
                override fun onException(exception: Throwable?) {
                    TipsToast.showTips("onException${exception?.message}")
                }

                override fun onFailed(code: Int) {

                }

                override fun onSuccess(param: Void?) {

                }

            })
    }
